﻿using AutoMapper;
using MediatR;
using Traceability.App.Applications.Command.Enterprise;
using Traceability.Domain.Entity;
using Traceability.Domain.Repository;
using Traceability.Enum;

namespace Traceability.App.Applications.CommandHand.Enterprise
{
    public class UpdataEnterpriseCommandHand : IRequestHandler<UpdataEnterpriseCommand, ApiResult<int>>
    {
        private readonly  IBaseRepository<EnterpriseModel> _repository;
        private readonly IMapper mapper;

        public UpdataEnterpriseCommandHand(IBaseRepository<EnterpriseModel> repository, IMapper mapper)
        {
            _repository = repository;
            this.mapper = mapper;
        }

        public Task<ApiResult<int>> Handle(UpdataEnterpriseCommand request, CancellationToken cancellationToken)
        {
           var result=new ApiResult<int>();
            var enter=mapper.Map<EnterpriseModel>(request);

            _repository.Update(enter);
            result.Message = "成功";

           return Task.FromResult(result);
        }
    }
}
